<?php

	class wallRequests
	{
		
		public static function addRequest($req, $bot, $roundsToHoldPost=1)
		{
			include_once "Plugins/wall2/class/wallDB.php";
			
			$db = wallDB::getInstance();
			
			//get defaults for posting
			$postToFile 	= (int)$db->getSetting('postToFile');
			$postToCVEx 	= (int)$db->getSetting('postToCVEx');
			$postToCVLinkEx = (int)$db->getSetting('postToCVLinkEx');
			
			$ssql = "INSERT INTO myrequests VALUES ('$req',0,0,$postToFile, $postToCVEx, $postToCVLinkEx, 0, $roundsToHoldPost)";
			$db->query($ssql);
			
			$bot->SendMsg("Added Wall2 Post: ".$req);
		}
		
		public static function makeRequest($req, $bot)
		{
			$ld = new LocalData();
			
			
			$amf = $bot->streamPublish($req);
	   		$bod = $amf->_bodys[0];

	   		$arDump = array();
	   		
	   		$result = "OK";
	   		if (isset($bod->_value['data'][0]['data']['result']))
	   			$result = $bod->_value['data'][0]['data']['result'];
			
	   		$arDump["result"] = $result;
	   		
	   		$arDump["title"] = "title";
	   		//title  String Reference Jansen needs your help completing a collection.
	   		if (isset($bod->_value['data'][0]['data']['full']['title']))
	   			$arDump["title"] = htmlspecialchars($bod->_value['data'][0]['data']['full']['title'], ENT_QUOTES);

	   		$arDump["image"] = "";
	   		if (isset($bod->_value['data'][0]['data']['full']['media'][0]['src']))
	   			$arDump["image"] = $bod->_value['data'][0]['data']['full']['media'][0]['src'];

	   		$arDump["description"] = "description";
	   		if (isset($bod->_value['data'][0]['data']['full']['description']))
	   		$arDump["description"] = htmlspecialchars($bod->_value['data'][0]['data']['full']['description'], ENT_QUOTES);

	   		$arDump["butonHref"] = "";
	   		$arDump["butonText"] = "";
	   		// buttons  Array
	   		// href  String Reference  http://apps.facebook.com/cityville/neighbors.php?uid=20
	   		// text  String  Send collectables!
	   		if (isset($bod->_value['data'][0]['data']['full']['buttons'][0]['href']))
	   			$arDump["butonHref"] = $bod->_value['data'][0]['data']['full']['buttons'][0]['href'] ;
	   		
	   		if (isset($bod->_value['data'][0]['data']['full']['buttons'][0]['text']))
	   			$arDump["butonText"] = htmlspecialchars($bod->_value['data'][0]['data']['full']['buttons'][0]['text'], ENT_QUOTES);

	   		//  feed_type  String  wall-to-wall
	   		$arDump["feed_type"] = "feed_type";
	   		if (isset($bod->_value['data'][0]['data']['feed_type']))
	   			$arDump["feed_type"] = $bod->_value['data'][0]['data']['feed_type'];
	   		
	   		$arDump["pubDate"] = time();	
	   		$arDump["niceTime"] = date("M d, y H:m:i");//$ld->nicetime(time());
	   		
	   		
	   		return $arDump;
		}
		
		
		
		public static function postToCVExchange($reqDump)
		{
			
			$pData = array(
				'op' => "postFromBot",
			    'uri' => $reqDump["butonHref"]
			);
			
			
			$postdata = http_build_query( $pData );
			$opts = array('http' =>
			    array(
			        'method'  => 'POST',
			        'header'  => 'Content-type: application/x-www-form-urlencoded',
			        'content' => $postdata
			    ));
			$context  = stream_context_create($opts);
			$result = file_get_contents("http://www.cityvilleexchange.com/index.php", false, $context);
			return $result;
		}
		
		public static function postToCVLinkExchange($reqDump)
		{
			$pData = array(
			    'url' => $reqDump["butonHref"]
			);
			
			$postdata = http_build_query( $pData );
			$opts = array('http' =>
		    array(
		        'method'  => 'POST',
		        'header'  => 'Content-type: application/x-www-form-urlencoded',
		        'content' => $postdata
		    ));
			$context  = stream_context_create($opts);
			$result = file_get_contents("http://www.cityvillelinkexchange.com/core/plugin.php", false, $context);
			return $result;
		}
	}

?>